package trinnes.oliver.unimaas.smartpentalath.intelligence.features;

import trinnes.oliver.unimaas.smartpentalath.control.Game;
import trinnes.oliver.unimaas.smartpentalath.data.Cell;
import trinnes.oliver.unimaas.smartpentalath.data.Move;

/**
 *
 * @author Oliver Trinnes
 */
public class GroupSumFeature extends Feature
{

  public GroupSumFeature(int weight)
  {
    super(weight);
  }

  public int getValue(Game game, int move)
  {
    if (move == Move.SWAP)
      return 0;
    int sum = 0;
    for (int i = 0; i < game.getBoard().getCells().size(); i++)
    {
      Cell cell = game.getBoard().getCells().get(i);
      if (cell.getPiece().equals(game.getCurrentPlayer().getPiece()))
      {
        Cell[] neighbors = cell.getNeighbors();
        for (Cell neighbor : neighbors)
          if (neighbor != null && neighbor.getPiece().equals(cell.getPiece()))
            sum++;
      }
    }
    return sum;
  }
}
